package cn.xuguowen.user.designPatten.strategy.hsp.strategy;

import java.util.Objects;

/**
 * ClassName: Duck
 * Package: cn.xuguowen.user.designPatten.strategy.hsp.tradition
 * Description:
 * 鸭子抽象类
 * @Author 徐国文
 * @Create 2023/4/28 12:10
 * @Version 1.0
 */
public abstract class Duck {

    // 聚合飞行策略接口
    protected FlyBehavior flyBehavior;

    protected QuakeBehavior quakeBehavior;

    public void setFlyBehavior(FlyBehavior flyBehavior,QuakeBehavior quakeBehavior) {
        this.flyBehavior = flyBehavior;
        this.quakeBehavior = quakeBehavior;
    }

    protected abstract void display();

    protected void quake() {
        if (Objects.nonNull(quakeBehavior)) {
            quakeBehavior.quake();
        }
    }

    protected  void fly() {
        if (Objects.nonNull(flyBehavior)) {
            flyBehavior.fly();
        }
    }
}
